package com.t194.service.impl;

import com.github.pagehelper.PageHelper;
import com.t194.entity.User;
import com.t194.mapper.UserMapper;
import com.t194.service.UserService;
import com.t194.util.PageResult;
import com.t194.util.UserDto;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public void grant(Integer userId, Integer roleId) {
        userMapper.update(userId, roleId);
    }

    @Override
    public List<User> searchAll() {
        List<User> list = userMapper.findAll();
        return list;
    }
    @Override
    public PageResult searchPagination(Integer offset, Integer limit, UserDto dto) {
        PageHelper.offsetPage(offset, limit);
        List<User> list = userMapper.findByDto(dto);
        return new PageResult(list);
    }

    @Override
    public User login(String userCode) {
        return userMapper.findByUserCode(userCode);
    }


}
